//判断有没有登录
import router from "./index";
//useStore只能在setup中使用
import store from "@/store/index";
import { getApi } from "@/api/index.js"
//全局守卫

router.beforeEach((to, from, next) => {
  getApi.getUser({ pagenum: 1, pagesize: 1 }).then(mes => {
    if (to.name === "Login") {
      //判断是否在登录页面
      if (mes.data) {
        next({ name: "Index" })
      } else {
        next()
      }
    } else {
      //若不在登录页，没登录就跳登录页去，有token有不变
      if (mes.data) {
        next()
      } else {
        store.commit("logout")
      }
    }
  })

});
